﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VersionComparer.Comparer;

namespace VersionComparer.DataModel
{
    [Serializable]
    public class ValueItem : ComparableItem
    {
        string description;

        public ValueItem()
        {
        }
        public ValueItem(ComparableItem parent, string name, bool value) 
            : this ( parent, name , value.ToString ())
        {
        }

        public ValueItem(ComparableItem parent, string name , string value): base ( parent)
        {
            string text = string.Format("{0} = {1}", name, value);
            base.Text = text;
            base.FullText = text;
            description = text;
            Value = value;
            Name = name;
        }

        public override string Description
        {
            get
            {
                return description;
            }
            set
            {
                description = value;
            }
        }
        public string Name
        {
            get;
            private set;
        }

        public string Value
        {
            get;
            private set;
        }
        
        protected override int CompareToItem(ComparableItem other)
        {
            ValueItem otherValue = other as ValueItem ;

            int result = otherValue.Name.CompareTo(Name);
            if (result != 0)
                return result * 2;
            return otherValue.Value.CompareTo(Value);
        }

        protected override int HashCodeForMatch
        {
            get
            {
                return Name.GetHashCode();
            }
        }

        public override double Matches(ComparisonAlgorithm algorithm, ComparableItem other)
        {
            return (other as ValueItem).Name == Name ? Match.CertainMatch : Match.NoMatch;
        }
         
    }
}
